package data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

import pojo.Book;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import jsm.comsuner.JmsConsumer;
import dao.BookDao;
import dao.impl.BookDaoImpl;

public class DataLoad implements Runnable{
	
	private BookDao bookDao;
	private JmsConsumer consumer;
	private Timer timer;
	private Vector<Book> vector;
	public DataLoad(){
		bookDao = new BookDaoImpl();
		consumer = new JmsConsumer();
		timer = new Timer();
		vector = new Vector<Book>();
		timer.schedule(new TimerTask() {
			
			@Override
			public void run() {
//				bookDao
				
			}
		}, 1000);
	}
	
	public void run() {
//		List<Book> books = new ArrayList<Book>();
		ObjectMapper mapper = new ObjectMapper();
		while (true) {
			String bookString= consumer.consume();
			Book book;
			try {
				book = mapper.readValue(bookString, Book.class);
				bookDao.addBook(book);
			} catch (JsonParseException e) {
				e.printStackTrace();
			} catch (JsonMappingException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
			
	}
	
	

}
